#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :file_demo.py
# @Time      :2023/6/30 
# @Author    :CL
# @email     :1037654919@qq.com

import json
import pandas as pd
import os
import shutil

def readname(filePath):
    # filePath = 'pinterest/'
    name = os.listdir(filePath)
    return name
'TRON-3-0-opening-scene-part-2-Scene-1-5-924574467'
def clean_data(filePath):
    global  clean_count
    "清洗pinterest数据，先在文件夹里边搜索jpg,批量删除不要的图片，再打开程序，运行程序，删除相应文件夹：判断逻辑：文件夹里边文件小于3"
    print('开始清洗：',filePath)
    try:
        name = os.listdir(filePath)
        for i in name[:]:
            if i  == 'bianlilist.txt':
                continue
            path2= filePath+'{}/'.format(i)
            try:
                name2 = os.listdir(path2)
                # print(path2)
                if len(name2)<=2:
                    shutil.rmtree(path2)
                    print(filePath,i,len(name2))
                    clean_count+=1
                    continue

            except Exception as e:
                print(e)
    except Exception as e:
        print(e)
def count_file(path):
    try:
        name = os.listdir(path)
        return len(name)
    except:
        return 0



if __name__ == "__main__":
    name = readname('deviantart/')
    print(name)
    clean_count=0
    count_fi=0
    for na in name:
        if na in [ 'SUM.zip', 'carimage v0','SUM2.zip']:
            continue
        filepath = 'deviantart/{}/'.format(na)
        count_fi += count_file(filepath)
        # break

    print('count_fi:',count_fi)

    # for na in name:
    #     if na in [ 'SUM.zip', 'carimage v0','SUM2.zip']:
    #         continue
    #     filepath = 'deviantart/{}/'.format(na)
    #     clean_count += count_file(filepath)
    #     # break
    #
    # print('clean_count:',clean_count)
